Change configs to live in /etc/xen, other stuff in /var/xen.
Update xendomains to use xm.
INSTALL = $(wildcard *.py)
ETC = defaults democd netbsd xmdefaults
+ETCDIR = /etc/xen
INITD = init.d/xendomains init.d/xend
all:
install: all
mkdir -p $(prefix)/usr/bin
- mkdir -p $(prefix)/etc/xc
- mkdir -p $(prefix)/etc/xc/auto
+ mkdir -p $(prefix)$(ETCDIR)
+ mkdir -p $(prefix)$(ETCDIR)/auto
mkdir -p $(prefix)/etc/init.d
install -m0755 $(INSTALL) $(prefix)/usr/bin
for i in $(ETC); \
- do [ -a $(prefix)/etc/xc/$$i ] || \
- install -m0644 $$i $(prefix)/etc/xc; \
+ do [ -a $(prefix)/$(ETCDIR)/$$i ] || \
+ install -m0644 $$i $(prefix)$(ETCDIR); \
done
install -m0755 $(INITD) $(prefix)/etc/init.d
INITD=/etc/init.d/
+AUTODIR=/etc/xen/auto
+LOCKFILE=/var/lock/subsys/xendomains
+
if [ -e /lib/lsb ]; then
# assume an LSB-compliant distro (Debian with LSB package,
# recent-enough SuSE, others...)
start() {
- if [ -f /var/lock/subsys/xendomains ]; then return; fi
+ if [ -f $LOCKFILE ]; then return; fi
echo -n $"Starting auto Xen domains:"
- # we expect config scripts for auto starting domains to be in
- # /etc/xc/auto/ - they could just be symlinks to files elsewhere
- if [ -d /etc/xc/auto ] &&
- [ $(ls /etc/xc/auto/ | wc -l) -gt 0 ]; then
+ # We expect config scripts for auto starting domains to be in
+ # AUTODIR - they could just be symlinks to files elsewhere
+ if [ -d $AUTODIR ] && [ $(ls $AUTODIR | wc -l) -gt 0 ]; then
+ touch $LOCKFILE
- # create all domains with config files in /etc/xc/auto
- for dom in /etc/xc/auto/*; do
- xc_dom_create.py -q -f $dom
+ # Create all domains with config files in AUTODIR.
+ for dom in $AUTODIR/*; do
+ xm create --quiet --defaults $dom
if [ $? -ne 0 ]; then
RETVAL=$?
fi
done
- touch /var/lock/subsys/xendomains
fi
on_fn_exit
stop()
{
# NB. this shuts down ALL Xen domains (politely), not just the ones in
- # /etc/xc/auto/*
+ # AUTODIR/*
# This is because it's easier to do ;-) but arguably if this script is run
# on system shutdown then it's also the right thing to do.
echo -n $"Shutting down all Xen domains:"
- if [ -d /var/run/xendomains ] &&
- [ $(ls /var/run/xendomains/ | wc -l) -gt 0 ]; then
-
- cd /var/run/xendomains/
-
- for pid in *; do
-
- kill -s SIGTERM $(cat $pid)
-
- done
+ xm shutdown --all --wait --norestart
- fi
-
- sleep 3 # avoid races
-
- xc_dom_control.py shutdown all -w # shut down all domains, politely and wait
- # for all to exit
-
RETVAL=$?
- [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/xendomains
+ [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
on_fn_exit
}
# This does NOT necessarily restart all running domains: instead it
# stops all running domains and then boots all the domains specified in
-# /etc/xc/auto. If other domains have been started manually then they will
+# AUTODIR. If other domains have been started manually then they will
# not get restarted.
# Commented out to avoid confusion!
#
# ;;
status)
- xc_dom_control.py list
+ xm list
;;
*)
CMD_IFCONFIG = 'ifconfig'
CMD_ROUTE = 'route'
CMD_BRCTL = 'brctl'
+CMD_IPTABLES = "iptables"
DEFAULT_BRIDGE = 'nbe-br'
DEFAULT_INTERFACE = 'eth0'
d = { 'bridge': bridge, 'vif': vif_dev(dom, vif) }
cmd(CMD_BRCTL, 'delif %(bridge)s %(vif)s' % d)
+def vif_restrict_addr(dom, vif, addr, delete=0):
+ d = { 'vif': vif_dev(dom, vif), 'addr': addr}
+ if delete:
+ d['flag'] = '-D'
+ else:
+ d['flag' = '-A'
+ cmd(CMD_IPTABLES, '-P FORWARD DROP')
+ cmd(CMD_IPTABLES, '%(flag)s FORWARD -m physdev --physdev-in %(vif)s -s %(addr)s -j ACCEPT' % d)
+ cmd(CMD_IPTABLES, '%(flag)s FORWARD -m physdev --physdev-out %(vif)s -d %(addr)s -j ACCEPT' % d)
+
def bridge_create(bridge=None, **kwd):
"""Create a bridge.
Defaults hello time to 0, forward delay to 0 and stp off.
class XendRoot:
"""Root of the management classes."""
- lastboot_default = "/etc/xen/xend/lastboot"
+ lastboot_default = "/var/xen/lastboot"
"""Default path to the root of the database."""
- dbroot_default = "/etc/xen/xend/xenmgr-db"
+ dbroot_default = "/var/xen/xend-db"
"""Default path to the config file."""
- config_default = "/etc/xen/xenmgr-config.sxp"
+ config_default = "/etc/xen/xend-config.sxp"
"""Environment variable used to override config_default."""
config_var = "XEND_CONFIG"
use="Quiet.")
gopts.opt('path', val='PATH',
- fn=set_value, default='.:/etc/xc',
+ fn=set_value, default='.:/etc/xen',
use="Search path for default scripts.")
gopts.opt('defaults', short='f', val='FILE',
- fn=set_value, default='xmdefaults',
+ fn=set_value, default='defaults',
use="Use the given default script.")
gopts.opt('config', short='F', val='FILE',
config_vif.append(['bridge', bridge])
config_devs.append(['device', config_vif])
-## if vfr_ipaddr:
-## config_vfr = ['vfr']
-## idx = 0 # No way of saying which IP is for which vif?
-## for ip in vfr_ipaddr:
-## config_vfr.append(['vif', ['id', idx], ['ip', ip]])
-## config.append(config_vfr)
+def configure_vfr(config, opts):
+ if not opts.ipaddr: return
+ config_vfr = ['vfr']
+ idx = 0 # No way of saying which IP is for which vif?
+ for ip in opts.ipaddr:
+ config_vfr.append(['vif', ['id', idx], ['ip', ip]])
+ config.append(config_vfr)
def make_config(opts):
fn=set_true, default=0,
use='Wait for shutdown to complete.')
+gopts.opt('norestart', short='n',
+ fn=set_true, default=0,
+ use='Prevent domain restart.')
+
def shutdown(opts, doms, wait):
def domains():
return [ int(a) for a in server.xend_domains() ]